home *** CD-ROM | disk | FTP | other *** search
- //******************************************************************'
- //* *'
- //* TurboCAD for Windows *'
- //* Copyright (c) 1993 - 2004 *'
- //* International Microcomputer Software, Inc. *'
- //* (IMSI) *'
- //* All rights reserved. *'
- //* *'
- //******************************************************************'
-
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- enum ActiveTool
- {
- iSelectTool = 0,
- iAddLineSingleTool = 1,
- iAddCircleCenterAndPoint = 2
- }
- namespace TCGeometry
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- int firstPointX;
- int firstPointY;
- int previousMoveX;
- int previousMoveY;
- const string sTitle = "TCGeometry sample application !";
- private System.Windows.Forms.PictureBox picView;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Button cmCreateTCApp;
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.Button cmNewDrawing;
- private System.Windows.Forms.Button cmCloseDrawing;
- private System.Windows.Forms.Button cmZoomIn;
- private System.Windows.Forms.Button cmZoomOut;
- private System.Windows.Forms.Button cmZoomExtents;
- private System.Windows.Forms.Button cmCreateLine;
- private System.Windows.Forms.Button cmCreateCircle;
- private System.Windows.Forms.Button cmSelect;
- private System.Windows.Forms.StatusBar statusBar1;
- private System.Drawing.Drawing2D.GraphicsPath mousePath;
- private System.Drawing.Graphics pGraphics;
- private System.Drawing.Pen pPen;
- private System.Drawing.Pen pPenBackground;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- private System.Windows.Forms.TreeView propsPalette;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private TCengine tcApp;
- private bool m_bDrag;
- private ActiveTool m_iActiveTool;
- private System.Drawing.Color m_BackgroundColor;
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- picView.MouseMove += new System.Windows.Forms.MouseEventHandler(picView_MouseMove);
- picView.MouseDown += new System.Windows.Forms.MouseEventHandler(picView_MouseDown);
- mousePath = new System.Drawing.Drawing2D.GraphicsPath();
- pGraphics = picView.CreateGraphics ();
- pGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality ;
- //pGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality ;
- pPen = new Pen(System.Drawing.Color.Blue ,1);
- //pPenBackground = new Pen (picView.BackColor ,1);
- EnableButtons(false);
- tcApp = new TCengine ();
- firstPointX = firstPointY = -1;
- previousMoveX = previousMoveY = -1;
- m_bDrag = false;
- m_iActiveTool = ActiveTool.iSelectTool;
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- if (tcApp.m_gxApp != null)
- {
- tcApp.m_gxApp.Quit ();
-
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.picView = new System.Windows.Forms.PictureBox();
- this.cmCreateTCApp = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.cmNewDrawing = new System.Windows.Forms.Button();
- this.cmCloseDrawing = new System.Windows.Forms.Button();
- this.propsPalette = new System.Windows.Forms.TreeView();
- this.cmZoomIn = new System.Windows.Forms.Button();
- this.cmZoomOut = new System.Windows.Forms.Button();
- this.cmZoomExtents = new System.Windows.Forms.Button();
- this.cmCreateLine = new System.Windows.Forms.Button();
- this.cmCreateCircle = new System.Windows.Forms.Button();
- this.cmSelect = new System.Windows.Forms.Button();
- this.statusBar1 = new System.Windows.Forms.StatusBar();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.groupBox2.SuspendLayout();
- this.SuspendLayout();
- //
- // picView
- //
- this.picView.BackColor = System.Drawing.SystemColors.ControlLight;
- this.picView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.picView.Location = new System.Drawing.Point(24, 152);
- this.picView.Name = "picView";
- this.picView.Size = new System.Drawing.Size(528, 360);
- this.picView.TabIndex = 0;
- this.picView.TabStop = false;
- //
- // cmCreateTCApp
- //
- this.cmCreateTCApp.Location = new System.Drawing.Point(32, 32);
- this.cmCreateTCApp.Name = "cmCreateTCApp";
- this.cmCreateTCApp.Size = new System.Drawing.Size(64, 24);
- this.cmCreateTCApp.TabIndex = 1;
- this.cmCreateTCApp.Text = "Create";
- this.cmCreateTCApp.Click += new System.EventHandler(this.cmCreateTCApp_Click);
- //
- // groupBox1
- //
- this.groupBox1.Location = new System.Drawing.Point(24, 8);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(216, 56);
- this.groupBox1.TabIndex = 2;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "Application";
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.cmNewDrawing);
- this.groupBox2.Controls.Add(this.cmCloseDrawing);
- this.groupBox2.Location = new System.Drawing.Point(264, 8);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(264, 56);
- this.groupBox2.TabIndex = 2;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "Drawing";
- //
- // cmNewDrawing
- //
- this.cmNewDrawing.Location = new System.Drawing.Point(8, 24);
- this.cmNewDrawing.Name = "cmNewDrawing";
- this.cmNewDrawing.Size = new System.Drawing.Size(64, 24);
- this.cmNewDrawing.TabIndex = 1;
- this.cmNewDrawing.Text = "New";
- this.cmNewDrawing.Click += new System.EventHandler(this.cmNewDrawing_Click);
- //
- // cmCloseDrawing
- //
- this.cmCloseDrawing.Location = new System.Drawing.Point(88, 24);
- this.cmCloseDrawing.Name = "cmCloseDrawing";
- this.cmCloseDrawing.Size = new System.Drawing.Size(64, 24);
- this.cmCloseDrawing.TabIndex = 1;
- this.cmCloseDrawing.Text = "Close";
- this.cmCloseDrawing.Click += new System.EventHandler(this.cmCloseDrawing_Click);
- //
- // propsPalette
- //
- this.propsPalette.ImageIndex = -1;
- this.propsPalette.Location = new System.Drawing.Point(576, 152);
- this.propsPalette.Name = "propsPalette";
- this.propsPalette.SelectedImageIndex = -1;
- this.propsPalette.Size = new System.Drawing.Size(240, 376);
- this.propsPalette.TabIndex = 3;
- //
- // cmZoomIn
- //
- this.cmZoomIn.Location = new System.Drawing.Point(32, 80);
- this.cmZoomIn.Name = "cmZoomIn";
- this.cmZoomIn.Size = new System.Drawing.Size(64, 24);
- this.cmZoomIn.TabIndex = 1;
- this.cmZoomIn.Text = "Zoom In";
- this.cmZoomIn.Click += new System.EventHandler(this.cmZoomIn_Click);
- //
- // cmZoomOut
- //
- this.cmZoomOut.Location = new System.Drawing.Point(112, 80);
- this.cmZoomOut.Name = "cmZoomOut";
- this.cmZoomOut.Size = new System.Drawing.Size(64, 24);
- this.cmZoomOut.TabIndex = 1;
- this.cmZoomOut.Text = "Zoom Out";
- this.cmZoomOut.Click += new System.EventHandler(this.cmZoomOut_Click);
- //
- // cmZoomExtents
- //
- this.cmZoomExtents.Location = new System.Drawing.Point(200, 80);
- this.cmZoomExtents.Name = "cmZoomExtents";
- this.cmZoomExtents.Size = new System.Drawing.Size(88, 24);
- this.cmZoomExtents.TabIndex = 1;
- this.cmZoomExtents.Text = "Zoom Extents";
- this.cmZoomExtents.Click += new System.EventHandler(this.cmZoomExtents_Click);
- //
- // cmCreateLine
- //
- this.cmCreateLine.Location = new System.Drawing.Point(304, 80);
- this.cmCreateLine.Name = "cmCreateLine";
- this.cmCreateLine.Size = new System.Drawing.Size(64, 24);
- this.cmCreateLine.TabIndex = 1;
- this.cmCreateLine.Text = "Add Line";
- this.cmCreateLine.Click += new System.EventHandler(this.cmCreateLine_Click);
- //
- // cmCreateCircle
- //
- this.cmCreateCircle.Location = new System.Drawing.Point(384, 80);
- this.cmCreateCircle.Name = "cmCreateCircle";
- this.cmCreateCircle.Size = new System.Drawing.Size(64, 24);
- this.cmCreateCircle.TabIndex = 1;
- this.cmCreateCircle.Text = "Add Circle";
- this.cmCreateCircle.Click += new System.EventHandler(this.cmCreateCircle_Click);
- //
- // cmSelect
- //
- this.cmSelect.Location = new System.Drawing.Point(464, 80);
- this.cmSelect.Name = "cmSelect";
- this.cmSelect.Size = new System.Drawing.Size(64, 24);
- this.cmSelect.TabIndex = 1;
- this.cmSelect.Text = "Select";
- this.cmSelect.Click += new System.EventHandler(this.cmSelect_Click);
- //
- // statusBar1
- //
- this.statusBar1.Location = new System.Drawing.Point(0, 519);
- this.statusBar1.Name = "statusBar1";
- this.statusBar1.Size = new System.Drawing.Size(824, 22);
- this.statusBar1.TabIndex = 4;
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(576, 120);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(144, 24);
- this.label1.TabIndex = 5;
- this.label1.Text = "Properties:";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(24, 120);
- this.label2.Name = "label2";
- this.label2.TabIndex = 6;
- this.label2.Text = "Active Tool :";
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(144, 120);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(208, 23);
- this.label3.TabIndex = 7;
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.CausesValidation = false;
- this.ClientSize = new System.Drawing.Size(824, 541);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.statusBar1);
- this.Controls.Add(this.propsPalette);
- this.Controls.Add(this.cmCreateTCApp);
- this.Controls.Add(this.picView);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.cmZoomIn);
- this.Controls.Add(this.cmZoomOut);
- this.Controls.Add(this.cmZoomExtents);
- this.Controls.Add(this.cmCreateLine);
- this.Controls.Add(this.cmCreateCircle);
- this.Controls.Add(this.cmSelect);
- this.MaximizeBox = false;
- this.Name = "Form1";
- this.groupBox2.ResumeLayout(false);
- this.ResumeLayout(false);
-
- }
- #endregion
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
-
- private void cmCreateTCApp_Click(object sender, System.EventArgs e)
- {
- tcApp.CreategxApp ();
- }
-
- private void cmNewDrawing_Click(object sender, System.EventArgs e)
- {
- tcApp.CreateNewDrawing();
- IMSIGX.Property pProp;
- object varVal = "PaperColor";
- int lcolor;
- pProp = tcApp.m_gxApp.Properties.get_Item(ref varVal);
- lcolor =(int) pProp.get_Value( 0);
- m_BackgroundColor = picView.BackColor;
- picView.BackColor = System.Drawing.ColorTranslator.FromWin32 (lcolor);
- pPenBackground = new Pen (picView.BackColor ,1);
- tcApp.CreategxView ((int)picView.Handle);
- tcApp.m_gxView.ZoomToExtents ();
- EnableButtons(true);
- this.Text = sTitle + " ------ "+ tcApp.m_gxDrawing.Name ;
- }
-
- private void cmCreateLine_Click(object sender, System.EventArgs e)
- {
- tcApp.m_gxDrawing.Graphics.Unselect ();
- tcApp.m_gxView.Refresh ();
- m_iActiveTool = ActiveTool.iAddLineSingleTool;
- UpdatePrompt();
- }
- void EnableButtons(bool bVal)
- {
- cmCloseDrawing.Enabled = bVal;
- cmZoomIn.Enabled = bVal;
- cmZoomOut.Enabled = bVal;
- cmZoomExtents.Enabled = bVal;
- cmCreateLine.Enabled = bVal;
- cmCreateCircle.Enabled = bVal;
- cmSelect.Enabled = bVal;
- m_iActiveTool = ActiveTool.iSelectTool;
- UpdatePrompt();
- }
-
- private void cmCloseDrawing_Click(object sender, System.EventArgs e)
- {
- object missing = null;
- m_bDrag = false;
- pPenBackground.Dispose ();
- tcApp.m_gxDrawing.Close (ref missing, ref missing, ref missing);
- tcApp.m_gxDrawing = null;
- tcApp.m_gxView = null;
- EnableButtons(false);
- Form1.ActiveForm.Text = sTitle;
- picView.BackColor = m_BackgroundColor;
- picView.Refresh ();
- statusBar1.Text = "";
- }
-
- private void picView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- // Update the mouse path that is drawn onto the Panel.
- UpdatePrompt();
- if (!m_bDrag)
- return;
-
- int mouseX = e.X;
- int mouseY = e.Y;
- float r = 0;
-
- switch (m_iActiveTool)
- {
- case ActiveTool.iAddLineSingleTool:
- {
- if (m_bDrag == true)
- {
- // draw previous state of line with background color to hide it
- pGraphics.DrawLine (pPenBackground,firstPointX,firstPointY,previousMoveX, previousMoveY);
- // draw current staet of line
- pGraphics.DrawLine (pPen,firstPointX,firstPointY,mouseX, mouseY);
- }
- }
- break;
- case ActiveTool.iAddCircleCenterAndPoint:
- {
- // calculate radius for previous state of the circle
- r = (float)System.Math.Sqrt ((firstPointX - previousMoveX)*(firstPointX - previousMoveX) + (firstPointY - previousMoveY) * (firstPointY - previousMoveY));
- if (r != 0)
- {
- // hide previous state of circle by draw it with background color
- pGraphics.DrawArc (pPenBackground, firstPointX - r, firstPointY - r , 2*r, 2*r, 0, 360);
- }
- // calculate radius of circle for current state
- r = (float)System.Math.Sqrt ((firstPointX - mouseX)*(firstPointX - mouseX) + (firstPointY - mouseY) * (firstPointY - mouseY));
- if (r != 0)
- {
- // draw current state of the circle
- pGraphics.DrawArc (pPen, firstPointX - r, firstPointY - r , 2*r, 2*r, 0, 360);
- }
- }
- break;
- }
- previousMoveX = mouseX;
- previousMoveY = mouseY;
-
- if (tcApp.m_gxView !=null)
- {
- tcApp.m_gxView.Refresh ();
- }
- return;
-
- }
- private void picView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- // Update the mouse path that is drawn onto the Panel.
- IMSIGX.IGraphic gxGraphic;
- int mouseX = e.X;
- int mouseY = e.Y;
- if (tcApp.m_gxView == null)
- return;
- if (e.Button == MouseButtons.Left)
- {
- if (m_iActiveTool != ActiveTool.iSelectTool )
- {
- // if firstPointX nad firstPointY equal -1 it means that tool just started and
- // is in first click mode
- if (firstPointY == -1 && firstPointX == -1)
- {
- // store coordinates of first click
- firstPointX = mouseX;
- firstPointY = mouseY;
- // switch to second click mode
- m_bDrag = true;
- UpdatePrompt();
- return;
- }
- }
-
- switch (m_iActiveTool)
- {
- case ActiveTool.iSelectTool :
- {
- tcApp.m_gxDrawing.Graphics.Unselect ();
- IMSIGX.IGraphic gxSelectedGraphic = tcApp.SelectGraphic(mouseX, mouseY);
- FillPropertiesPalette(gxSelectedGraphic);
- tcApp.m_gxView.Refresh ();
- }
- break;
-
- case ActiveTool.iAddLineSingleTool :
- {
- gxGraphic = tcApp.AddLineSingle (firstPointX,firstPointY, mouseX, mouseY);
- m_bDrag = false;
- firstPointX = -1;
- firstPointY = -1;
- previousMoveX = -1;
- previousMoveY = -1;
- }
- break;
-
- case ActiveTool.iAddCircleCenterAndPoint :
- {
- gxGraphic = tcApp.AddCircleCenterAndPoint (firstPointX,firstPointY, mouseX, mouseY);
- m_bDrag = false;
- firstPointX = -1;
- firstPointY = -1;
- previousMoveX = -1;
- previousMoveY = -1;
- }
- break;
-
-
-
- }
- picView.Refresh ();
- tcApp.m_gxView.Refresh ();
- UpdatePrompt();
- return;
- }
- }
- private void cmZoomExtents_Click(object sender, System.EventArgs e)
- {
- if (tcApp.m_gxView != null)
- {
- picView.Refresh ();
- tcApp.m_gxView.ZoomToExtents ();
- }
- }
-
- private void cmSelect_Click(object sender, System.EventArgs e)
- {
- statusBar1.Text = "Select object";
- m_iActiveTool = ActiveTool.iSelectTool ;
- UpdatePrompt();
- FillPropertiesPalette(null);
- }
-
- private void cmCreateCircle_Click(object sender, System.EventArgs e)
- {
- tcApp.m_gxDrawing.Graphics.Unselect ();
- tcApp.m_gxView.Refresh ();
- m_iActiveTool = ActiveTool.iAddCircleCenterAndPoint;
- UpdatePrompt();
- }
- private void UpdatePrompt()
- {
- statusBar1.Text = "";
- switch (m_iActiveTool)
- {
- case ActiveTool.iSelectTool :
- {
- statusBar1.Text = "Select Object";
- label3.Text = "Select Tool";
- }
- break;
- case ActiveTool.iAddLineSingleTool:
- {
- if (m_bDrag == false)
- {
- statusBar1.Text = "Define the start point of the line";
- label3.Text = "Add Single Line";
- }
- else
- {
- statusBar1.Text = "Define the end point of the line";
- label3.Text = "Add Single Line";
- }
- }
- break;
- case ActiveTool.iAddCircleCenterAndPoint:
- {
- if (m_bDrag == false)
- {
- statusBar1.Text = "Define the center point of the circle";
- label3.Text = "Add Circle Center and Point";
- }
- else
- {
- statusBar1.Text = "Define a second point of the circle's circumferences";
- label3.Text = "Add Circle Center and Point";
- }
-
- }
- break;
-
- }
- }
-
- private void FillPropertiesPalette(IMSIGX.IGraphic gxGraphic)
- {
- //propsPalette.TopNode.Collapse();
- ClearPropertiesPalette();
- if (gxGraphic == null)
- return;
- // fill common info
- TreeNode pRootNode, pchildNode;
- IMSIGX.Vertices gxVertices;
- IMSIGX.IVertex gxVertex;
- object var;
- double vardblVal;
- double radius;
- double xCenter, yCenter, X,Y,Z;
- vardblVal = 0;
- pRootNode = propsPalette.Nodes.Add ("General");
- pRootNode.Nodes.Add ("GraphicID = " + gxGraphic.ID );
- pRootNode.Nodes.Add ("Type = " + gxGraphic.Type );
- pRootNode = propsPalette.Nodes.Add ("Geometry Information");
- gxVertices = gxGraphic.Vertices;
- if (gxGraphic.TypeByValue == IMSIGX.ImsiGraphicType.imsiArc )
- {
-
- pchildNode = pRootNode.Nodes.Add ("Center");
- var = 0;
- gxVertex = gxVertices.get_Item(ref var);
- xCenter = gxVertex.X;
- yCenter = gxVertex.Y;
- vardblVal = gxVertex.X ;
- pchildNode.Nodes.Add ("X = " + vardblVal.ToString ());
- vardblVal = gxVertex.Y;
- pchildNode.Nodes.Add ("Y = " + vardblVal.ToString ());
- pchildNode.Nodes.Add ("Z = 0");
-
- var = 1;
- gxVertex = gxVertices.get_Item(ref var);
- X = gxVertex.X;
- Y = gxVertex.Y;
- radius = (float)System.Math.Sqrt ((xCenter - X)*(xCenter - X) + (yCenter - Y) * (yCenter - Y));
- pchildNode = pRootNode.Nodes.Add ("Radius " + radius.ToString ());
- }
- else if (gxGraphic.TypeByValue == IMSIGX.ImsiGraphicType.imsiPolyline )
- {
- int n, i;
- n = gxVertices.Count;
- pRootNode = pRootNode.Nodes.Add ("Vertices");
- for (i = 0; i < n; i++)
- {
- var = i;
- gxVertex = gxVertices.get_Item(ref var);
- pchildNode = pRootNode.Nodes.Add ("V " + var.ToString ());
- X = gxVertex.X;
- Y = gxVertex.Y;
- Z = gxVertex.Z;
- pchildNode.Nodes.Add ("X = " + X.ToString ());
- pchildNode.Nodes.Add ("Y = " + Y.ToString ());
- pchildNode.Nodes.Add ("Z = " + Z.ToString ());
- }
-
- }
- gxGraphic.Drawing.Graphics.Unselect ();
- gxGraphic.Selected = true;
- tcApp.m_gxView.Refresh ();
- propsPalette.ExpandAll ();
- }
- private void ClearPropertiesPalette()
- {
- propsPalette.Nodes.Clear ();
-
- }
-
- private void cmZoomIn_Click(object sender, System.EventArgs e)
- {
- tcApp.Zoom (0.8);
- picView.Refresh ();
- tcApp.m_gxView.Refresh ();
- }
-
- private void cmZoomOut_Click(object sender, System.EventArgs e)
- {
- tcApp.Zoom (1.2);
- picView.Refresh ();
- tcApp.m_gxView.Refresh ();
- }
- }
- }
-